package com.starlight.flower_server.domain.service.impl;

import com.starlight.flower_server.domain.TotalData;
import com.starlight.flower_server.domain.role.data.RoleData;
import com.starlight.flower_server.domain.service.RoleService;
import com.starlight.flower_server.infrastructure.entity.Role;
import com.starlight.flower_server.infrastructure.repository.RoleRepository;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author yfy2001
 * @date 2023/4/5 15:30
 */
@Service
public class RoleServiceImpl implements RoleService {

    @Resource
    private RoleRepository roleRepository;

    @Override
    public TotalData<RoleData> queryAllRoleData() {
        TotalData<RoleData> data=new TotalData<>();
        List<Role> roleList=roleRepository.queryAll();
        List<RoleData> roleDataList=roleList
                .stream().map(role -> {
                    RoleData roleData=new RoleData();
                    BeanUtils.copyProperties(role,roleData);
                    return roleData;
                }).toList();
        return data;
    }
}
